﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using C.Entities;
using C.Unite;
using ChanExt;
using System.Text;

namespace ArtLand.OA.Project.PublicModel
{
    public partial class ArtView : CommonPageBase
    {
        public string Title = "";
        public string Addemp = "";
        public string AddTime = "";
        public string StartTime = "";
        public string EndTime = "";
        public string Contents = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    Proj_Article pa = TbsDbSession.Default.From<Proj_Article>().Where(Proj_Article._.ID == int.Parse(Request["id"])).ToFirst();
                    Title = pa.BTOPIC;
                    Addemp = pa.Adder;
                    AddTime = pa.AddTime.Value.ToString("yyyy年MM月dd日 hh时mm分");
                    StartTime = pa.STDATE.Value.ToString("yyyy年MM月dd日 hh时mm分");
                    EndTime = pa.EDDATE.Value.ToString("yyyy年MM月dd日 hh时mm分");
                    //lab1.Text = Contents;
                    Contents = pa.COTENT;



                    LableBind();



                    //<div class="news_news_view_comment_items news_news_view_comment_items2">
                    //    <div class="news_news_view_comment_items_title">#2&nbsp;&nbsp;发表人: <a>超级管理员</a>&nbsp;&nbsp;发表时间: 2013年12月23日 22:06</div>
                    //    <div class="news_news_view_comment_items_body">124</div>
                    //</div>
                    //<div class="news_news_view_comment_items ">
                    //    <div class="news_news_view_comment_items_title">#3&nbsp;&nbsp;发表人: <a>超级管理员</a>&nbsp;&nbsp;发表时间: 2013年12月23日 22:05</div>
                    //    <div class="news_news_view_comment_items_body">123</div>
                    //</div>


                }

            }
        }

        protected void LableBind()
        {
            StringBuilder sb = new StringBuilder();
            List<Proj_ArtComment> commentList = TbsDbSession.Default.From<Proj_ArtComment>().Where(Proj_ArtComment._.ArtID == int.Parse(Request["id"])).ToList();
            int c = 0;
            sb.Append("<div class=\"news_news_view_comment_title\">关于本文的评论( <span style=\"color: red\">" + commentList.Count + "</span> )</div>");
            foreach (Proj_ArtComment item in commentList)
            {
                c++;
                sb.Append("<div class=\"news_news_view_comment_items \">");
                sb.Append("<div class=\"news_news_view_comment_items_title\">#"+c.ToString()+"&nbsp;&nbsp;发表人: <a>" + item.Adder + "</a>&nbsp;&nbsp;发表时间: " + item.AddTime.Value.ToString("yyyy年MM月dd日 hh:mm") + "</div>");
                sb.Append("<div class=\"news_news_view_comment_items_body\">" + item.Comment + "</div>");
                sb.Append("</div>");
            }

            lbl_Comment.Text = sb.ToString();
        }

        protected void Unnamed_Click(object sender, EventArgs e)
        {
            Proj_ArtComment com = new Proj_ArtComment();
            com.DeAttach();
            com.ArtID = int.Parse(Request["id"]);
            com.AddUid = CookInfo.EAdminid();
            com.AddTime = DateTime.Now;
            com.Adder = CookInfo.EAdminTrueName();
            com.Comment = txt_Comment.Text;
            TbsDbSession.Default.Insert<Proj_ArtComment>(com);
            LableBind();
        }



    }
}